package cc.fs.zhihuapp.utils;

import android.net.Uri;
import android.os.Parcel;
import android.text.ParcelableSpan;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.View;

import java.util.regex.Pattern;

/**
 * Created by fostion on 2015/8/31.
 */
public class MySpan extends ClickableSpan implements ParcelableSpan {
    private String content;

    public MySpan(String content) {
        this.content = content;
    }

    @Override
    public void onClick(View widget) {

        Log.e("--------", "---------------------------- ");
        Log.e("----click----", content);
        Log.e("--------", "---------------------------- ");

        if (content.startsWith("[100]")) {
            Log.e("--------", "---  100  ----- ");
        }

        if (content.startsWith("[200]")) {
            Log.e("--------", "---  200  ----- ");
        }

        if (content.startsWith("[300]")) {
            Log.e("--------", "---  300  ----- ");
        }

    }

    public void onLongClick(View widget){
        Log.e("--------", "---------------------------- ");
        Log.e("----long click----", content);
        Log.e("--------", "---------------------------- ");
    }

    @Override
    public int getSpanTypeId() {
        return 11;
}

    @Override
    public int describeContents() {
        return 0;
    }

    public MySpan(Parcel src) {
        content = src.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(content);
    }

    //正则表达式 识别字符中的关键字
    public static class MySpanPattern {
        //识别http
        public static final Pattern WEB_URL = Pattern
                .compile("http://[a-zA-Z0-9+&@#/%?=~_\\-|!:,\\.;]*[a-zA-Z0-9+&@#/%=~_|]");
        //识别#
        public static final Pattern TOPIC_URL = Pattern
                .compile("#[\\p{Print}\\p{InCJKUnifiedIdeographs}&&[^#]]+#");
        //识别@
        public static final Pattern MENTION_URL = Pattern .compile("@[\\w\\p{InCJKUnifiedIdeographs}-]{1,26}");
        //识别表情
        public static final Pattern EMOTION_URL = Pattern.compile("\\[(\\S+?)\\]");
        //识别头 将会添加到识别后的字符串上面
        public static final String SCHEME100 = "[100]";
        public static final String SCHEME200 = "[200]";
        public static final String SCHEME300 = "[300]";
    }

}
